package com.nlgc365.designpattern.Chapter04_Pattern.Creation.P02_Factory.Calculator.SimpleFactory;

import java.util.HashMap;

/**
 * 简单工厂: 目的, 分离对象创建的过程.
 */
public class CalculatorFactory {
    private static HashMap<String, Calculator> calculators;

    static {
        // 问题: 对于新增或者修改需求来说, 这里不满足开闭原则.
        calculators = new HashMap<>();
        calculators.put("+", new CalculatorAddImpl());
        calculators.put("-", new CalculatorSubImpl());
        calculators.put("*", new CalculatorMultiImpl());
        calculators.put("/", new CalculatorDivideImpl());
        calculators.put("%", new CalculatorRemainImpl());
    }

    public static Calculator getCalculator(String symbol) {
        return calculators.get(symbol);
    }
}
